<template>
  <header class="head-nav">
    <el-row>
      <el-col :span="12" class="logo-container">
        <img src="" class="logo" alt="" />
        <span class="title">在线后台系统</span>
      </el-col>
      <el-col :span="3" class="user">
        <div class="userinfo">
          <img :src="user.avatar" class="avatar" alt="" />
          <div class="welcome">
            <p class="name comename">欢迎</p>
            <p class="name avatarname">{{ user.name }}</p>
          </div>
          <span class="username"
            ><el-dropdown trigger="click" @command="setDialogInfo">
              <span class="el-dropdown-link">
                <i class="el-icon-caret-bottom el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="info">个人信息</el-dropdown-item>
                <el-dropdown-item command="logout">退出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown></span
          >
        </div>
      </el-col>
    </el-row>
  </header>
</template>

<script>
export default {
  name: 'head-nav',
  computed: {
    user () {
      return this.$store.getters.user
    }
  },
  methods: {
    setDialogInfo (cmdItem) {
      switch (cmdItem) {
        case 'info':
          this.showInfoList()
          break
        case 'logout':
          this.logout()
          break
      }
    },
    showInfoList () {
      this.$router.push('/infoshow')
    },
    logout () {
      //清除token
      localStorage.removeItem('eleToken')
      //清除 vuex store
      this.$store.dispatch('clearCurrentState')
      //跳转
      this.$router.push('/login')
    }
  }
}
</script>

<style scoped>
.head-nav {
  width: 100%;
  height: 60px;
  min-width: 600px;
  background-color: #324057;
  color: #fff;

  border-bottom: 1px solid #1f2d3d;
}
.logo-container {
  padding-left: 40px;
  font-size: 25px;
  line-height: 60px;
}
.user {
  float: right;
  padding: 0;
}
.userinfo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.avatar {
  width: 40px;
  height: 40px;
  margin-right: 8px;
  border-radius: 20px;
}

.name {
  margin: 0;
  padding: 0;
  font-size: 12px;
}
.avatarname {
  font-weight: bold;
  color: deepskyblue;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.el-dropdown-link {
  color: #fff;
}
</style>